<template>
	<view>
		<view class="contain">
			<view class="navigationTop" >
				<view class="navigationImage" @tap="back">
					<image src="../../static/img/backWhite.png" mode="widthFix" ></image>
				</view>
				<view > 车票预订</view>
			</view>
			
			<view class="fareInfBox">
				<view class="depart">{{fareList.startStop}}</view>
				<view class="pathBox">
					<text>{{fareList.departureDay}}</text>
					<view class="pathImg">
						<image src="../../static/img/icon-directivity.png" mode="widthFix"></image>
					</view>
					<text>{{fareList.departureTime}}</text>
				</view>
				<view class="destination">
					<text>{{fareList.lastStop}}</text>
					<text>{{fareList.lastStop}}{{stationName}}</text>
				</view>
			</view>
		</view>
		
		<view class="riderBox">
			<view class="selectRider">
				<text>选择乘车人</text>
				<text>添加&修改  >> </text>
			</view>
			<view class="rider">
				<text class="riderName">Dooner</text>
				<text>4123454123441131123</text>
				<view class="circle"></view>
			</view>
		</view>
		
		<view class="riderPhone">
			<text>乘车人联系方式</text>
			<text>14750651287</text>
		</view>
		
		<view class="riderPhone">
			<text>订单总额</text>
			<text>￥{{fareList.busPrice}}</text>
		</view>
		
		<view class="selectPayBox">
			<view class="selectPay">选择支付方式</view>
			<view class="wxPayBox" @tap="handleWxPay">
				<view style="display: flex;align-items: center;">
					<view class="wxPayImg">
						<image src="../../static/img/icon-WeChat.png" mode="widthFix"></image>
					</view>
					
					<view class="wxText">
						<text>微信支付</text>
						<text>使用微信支付，安全便捷</text>
					</view>
				</view>
				<view class="circle" :style="{'background':isWxPay?'#EB6A58':''}" ></view>
			</view>
		</view>
		
		<view class="discounts">
			<text>选择优惠券</text>
			<view class="underImg">
				<image src="../../static/img/back.png" mode="widthFix"></image>
			</view>
		</view>
		
		<view class="hint" @tap="handleWarn">
			<view class="hintContent">
				<image src="../../static/img/icon-Help.png" mode="widthFix"></image>
				我已知晓<text>购票须知</text>内容
			</view>
			
			<view class="circle" :style="{'background':isWarm?'#EB6A58':''}" ></view>
		</view>
		
		<view class="submit" :style="{'background':(isWarm && isWxPay) ?'#F7C269':'#D9D9D9'}" @tap="submit">
			提交
		</view>
		
		<view class="mask" @click="isConfirm = false" v-show="isConfirm"></view>
		<view class="confirm" v-show="isConfirm">
			
			<view class="confirmImg">
				<image src="../../static/img/Logo-ERoad-文字版-1.png" mode="widthFix"></image>
				订单提交成功
			</view>
			<view class="operation">
				<view class="toOrder operationBox" @tap="toOrder">
					前往订单
				</view>
				<view class="toIndex operationBox" @tap="toIndex">
					返回首页
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				isWxPay:false,
				isWarm:false,
				isConfirm:false,
				fareList:{},
				stationName:""
			}
		},
		components: {
			
		},
		onLoad(options) {
			this.fareList = JSON.parse(decodeURIComponent(options.fareList))
			this.stationName = JSON.parse(decodeURIComponent(options.stationName))
			console.log(this.fareList)
			console.log(this.stationName)
		},
		methods: {
			back(){
				uni.navigateBack()
			},
			handleWarn(){
				this.isWarm = !this.isWarm
			},
			handleWxPay(){
				this.isWxPay = !this.isWxPay
			},
			
			async submit(){
				if(this.isWarm&&this.isWxPay){
					
					const userId = uni.getStorageSync('userId')
					const res = await this.$myRequest({
						url:"/order/new",
						method:"POST",
						data:{
							userId:userId,
							busId:this.fareList.busId
						}
					})
					if(res.data){
						this.isConfirm = true
					}
				}
			},
			toIndex(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			},
			
			toOrder(){
				uni.switchTab({
					url:'/pages/order/order'
				})
			}
		}
	}
</script>

<style lang="scss">
	.mask {
	  position: fixed;
	  top: 0;
	  left: 0;
	  right: 0;
	  bottom: 0;
	
	}
	.contain{
		background: #EB6A58;;
		.navigationTop{
			display: flex;
			width: 100%;
			height: 88rpx;
			padding-top: 88rpx;
			align-items: center;
			font-size: 36rpx;
			font-family: Inter, Inter;
			font-weight: bold;
			color: #fff;
			.navigationImage{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 88rpx;
				height: 88rpx;
				margin-right: 206rpx;
				image{
					width: 32rpx;
				}
			}
			
			.imgBox {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 88rpx;
				margin-left: 72rpx;
				.indexTopImg {
					width: 148rpx;
				}
			}
			 
		}
		
		.fareInfBox{
			display: flex;
			align-items: center;
			justify-content: space-around;
			width: 100%;
			height: 176rpx;			
			font-size: 36rpx;
			font-family: Inter, Inter;
			font-weight: 400;
			color: #FAFAFA;
			.pathBox{
				position: relative;
				height: 176rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				padding-bottom: 16rpx;
				box-sizing: border-box;
				text:nth-child(1){
					position: absolute;
					top: 56rpx;
					left: 28rpx;
					font-size: 22rpx;
				}
				text:nth-child(3){
					position: absolute;
					top: 92rpx;
					left: 28rpx;
					font-size: 32rpx;
				}
				.pathImg{
					width: 162rpx;
					image{
						width: 162rpx;
						height: 2rpx;
					}
				}
			}
			
			
			.depart{
				
			}
			
			.destination{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				text:nth-child(2){
					font-size: 24rpx;
				}
			}
			
		}
	}
	
	.riderBox{
		width: 100%;
		height: 190rpx;
		margin-top: 32rpx;
		background: #F7F7F7;
		.selectRider{
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #EB6A58;
			font-size: 24rpx;
			border-bottom:1rpx solid #EB6A58 ;
			height: 72rpx;
			font-family: Inter, Inter;
			font-weight: 400;
		}
		text:nth-child(1){
			margin-left: 36rpx;
		}
		text:nth-child(2){
			color: #333;
			margin-right: 36rpx;
		}
		.rider{
			height: 128rpx;
			display: flex;
			align-items: center;
			font-size: 28rpx;
			font-family: Inter, Inter;
			font-weight: 400;
			color: #333333;
			justify-content: space-between;
			.riderName{
				font-size: 36rpx;
				 margin-left: 34rpx;
			}
			text:nth-child(2){
				margin-left: 36rpx;
			}
			.circle{
				width: 48rpx;
				height: 48rpx;
				background: #EB6A58;
				border-radius: 48rpx;
				margin-right: 72rpx;
			}
		}
	}
	
	.riderPhone{
		height: 98rpx;
		background: #F7F7F7;
		margin-top: 32rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-family: Inter, Inter;
		font-weight: 400;
		text:nth-child(1){
			margin-left: 36rpx;
			font-size: 28rpx;			
			color: #545454;
		}
		text:nth-child(2){
			font-size: 36rpx;
			color: #333333;
			margin-right: 36rpx;
		}
	}
	
	.selectPayBox{
		margin-top: 32rpx;
		height: 189rpx;
		background: #F7F7F7;
		.selectPay{
			border-bottom:1rpx solid #EB6A58 ;
			height: 72rpx;
			display: flex;
			align-items: center;
			font-size: 24rpx;
			font-family: Inter, Inter;
			font-weight: 400;
			color: #EB6A58;
			padding-left: 36rpx;
		}
		.wxPayBox{
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 128rpx;
			.wxPayImg{
				width: 48rpx;
				margin-left: 44rpx;
				margin-right: 16rpx;
				image{
					width: 48rpx;
				}
			}
			.wxText{
				display: flex;
				flex-direction: column;
				font-family: Inter, Inter;
				font-weight: 400;
				float: left;
				text:nth-child(1){
					font-size: 28rpx;					
					color: #333333;
				}
				text:nth-child(2){
					font-size: 20rpx;
					color: #545454;
				}
			}
			.circle{
				width: 48rpx;
				height: 48rpx;
				background: #D9D9D9;
				border-radius: 48rpx;
				margin-right: 72rpx;
			}
		}
		
	}
	
	.discounts{
		height: 98rpx;
		background: #F7F7F7;
		margin-top: 32rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-family: Inter, Inter;
		font-weight: 400;		
		.underImg{
			width: 48rpx;
			margin-right: 72rpx;
			image{
				width: 48rpx;
				transform: rotate(-90deg);
			}
		}
		text:nth-child(1){
			margin-left: 36rpx;
			font-size: 28rpx;			
			color: #545454;
		}
	}
	
	.hint{
		height: 98rpx;
		background: #F7F7F7;
		margin-top: 32rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-family: Inter, Inter;
		font-weight: 400;
		color: #545454;
		font-size: 28rpx;
		.hintContent{
			margin-left: 36rpx;
			display: flex;
			height: 98rpx;
			align-items: center;
			image{
				width: 48rpx;
				margin-right: 8rpx;
			}
			text{
				color: #EB6A58;
			}
		}
		.circle{
			width: 48rpx;
			height: 48rpx;
			background: #D9D9D9;
			border-radius: 48rpx;
			margin-right: 72rpx;
		}
	}
	.submit{
		width: 400rpx;
		height: 118rpx;
		background: #D9D9D9;
		border-radius: 24rpx;
		margin: 44rpx auto auto auto;
		text-align: center;
		line-height: 118rpx;
		font-size: 40rpx;
		font-family: Inter, Inter;
		font-weight: 400;
		color: #545454;
	}
	
	.confirm{
		position: absolute;
		left: 110rpx;
		top: 508rpx;
		width: 434rpx;
		height: 290rpx;
		background: #fff;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #333333;
		justify-content: space-between;
		z-index: 2;
		.confirmImg{
			width: 192rpx;
			align-items: center;
			display: flex;
			flex-direction: column;
			margin-top: 48rpx;
			image{
				width: 124rpx;
			}
		}
		.operation{
			width: 100%;
			height: 100rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #545454;
			margin-bottom: 28rpx;
			.operationBox{
				width: 50%;
				height: 100rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}			
			.toOrder{
				border-right: 2rpx solid #A8A8A8;
			}
			.toIndex{
				color: #EB6A58;
			}
			
		}
	}
</style>
